<?php 
$discount_rate = false;
if ($this->session->userdata('discount_rate')){
	$discount_rate = $this->session->userdata('discount_rate');
}
?>
<div class="cart_container">
	

	<div class="recently-viewed rounded-corners light-brown-border">
		<div class="head cartHead">
			<h4><?=lang('my_cart')?></h4>
		</div>
	<div class="clear"></div>
	<div class="cartContent" >
	<div style="width:100%"> 
		<div class="cartImage  left upper"><strong>&nbsp;</strong></div>
		<div class="left  lpadding10 cartDetails upper"><strong><?=lang('product_name')?></strong></div>
		<div class="left lpadding10 cartSubtotal upper"><strong><?=lang('unic_price')?></strong></div>
		<div class="left lpadding10 upper"><strong><?=lang('qty')?></strong></div>
		<div class="left lpadding10 cartSubtotal upper"><strong><?=lang('subtotal')?></strong></div>
		<div class="clear"></div>
		<hr/>
		
	 </div>	
	<div class="clear"></div>

	<?php echo form_open('cart/updateCart', array('class'=>'cartFrm')); 
	$i = 0;
	foreach ($this->cart->contents() as $items){ 
		$i++;
		echo form_hidden($i.'_rowid', $items['rowid']); 
		$productOptiona = $this->cart->product_options($items['rowid'])	?>
			<div class="cartImage left">
				<div class="image-container left">
					<img src="<?php echo ASSETS_URL . 'catalog/small/' . $productOptiona["imageUrl"]?>" />
					<a class="zoom"href="<?php echo (file_exists(LARGE_IMAGE_URL . $productOptiona["imageUrl"]) ? LARGE_IMAGE_URL . $productOptiona["imageUrl"] : NORMAL_IMAGE_URL . $productOptiona["imageUrl"]) ?>"rel="shadowbox"></a>
			    </div>
			</div>	
			<div class="left lpadding10 cartDetails">
				<div class="product_name"><?php echo $items['name']; ?></div>
				<?php if ($this->cart->has_options($items['rowid']) == TRUE) { ?>
					<p>
						<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value){
							if($option_name == 'imageUrl')
								continue;
							?>
							<strong>
							<?php 
							switch ($option_name){
								case 'metal':
									echo lang('cart_metal');
									break;
								case 'colour':
									echo lang('colour');
									break;
								case 'carat_weight':
									echo lang('carat_weight');
									break;
								case 'diamond_size_text':
									echo lang('diamond_size_text');
									break;
								case 'ring_band_width':
									echo lang('ring_band_width');
									break;
								case 'engraving_text':
									echo lang('engraving_text');
									break;
								case 'special_requirements':
									echo lang('special_requirements');
									break;
								case 'ring_size':
									echo lang('ring_size');
									break;
									
							}
						?>
							:</strong> <?php echo $option_value; ?><br />
						<?php } ?>
					</p>
					<?php } ?>
					<a href="<?= site_url('cart/deleteItem/' . $items['rowid']) ?>" class="cart_btn_delete">
						<div class="delete_text product_name"><?=lang('remove_item')?></div>
					</a>
			</div>	
			<div class="left lpadding10 cartSubtotal">
				<?php echo $this->cart->format_number($exchange->transformPrice($items['subtotal'],$sel_currency, true, 0)) . ' ' . $sel_currency;?>
			</div>	
			<div class="left lpadding10">
				<?php echo form_input(array('name' => $i.'_qty', 'value' => $items['qty'], 'maxlength' => '2', 'size' => '1', 'id'=>'cartInput')); ?>
			</div>	
			<div class="left lpadding10 cartSubtotal">
				<?php echo $this->cart->format_number($exchange->transformPrice($items['subtotal'],$sel_currency, true, 0)) . ' ' . $sel_currency;?>
			</div>	
			<div class="clear"></div>
			<hr/>
				<?php 
			
		}

		$total = $exchange->transformPrice($this->cart->total(),$sel_currency, true, 0, $discount_rate);
		echo form_hidden('countItem',$i);
		?>
			<div class="clear"></div>
				<?php 	$bdata = array(
				    'name' => 'button',
				    'id' => 'button',
				    'value' => lang('update_cart'),
				    'class' => 'cart_btn_midle'
				);	?>
			<a href="<?php echo $backString; ?>" class="left">
				<div class="cart_btn_left"></div>
				<div class="cart_btn_midle"><?php echo lang('continue_shop') ?></div>
				<div class="cart_btn_right"></div>
			</a>
			<div class="right">	
				<div class="cart_btn_left"></div>
				<?php echo form_submit($bdata, ''); ?>
				<div class="cart_btn_right"></div>
			</div>
			<?php echo form_close();?>
			<div class="clear"></div>
			<hr/>
			<div id="question-status-error" class="message ui-state-error hide"></div>
			<input type="text" id="discount_code" value="<?=lang('discount_code_text')?>" style="color:#353535;background-color:#f5f5f5;border:1px solid #DDDDDD;" class="discount_code default-value" <?php echo  $discount_rate ? 'disabled="disabled"' : ''?>/>
			<div class="clear"></div>
			
			<a href="<?php echo  $discount_rate ? 'JavaScript:void(0)' : 'JavaScript:addDiscount()'?>" class="left">
				<div class="green_btn_left"></div>
				<div class="green_btn_midle"><?php echo lang('apply_discount') ?></div>
				<div class="green_btn_right"></div>
			</a>
			
			<div class="clear"></div>
			<hr/>
			<?php /*echo form_open('cart/checkout', array('class'=>'cartFrm', 'id' => 'goCheckout')); */?>
			<form action="cart/checkout" class='cartFrm' id ='goCheckout' method='get'>
		
			<div class="right">
				<ul class="cart-list">
					<li class="left-lsit">
						<strong><?=lang('advance_of_maney')?></strong>
					</li>
					<li class="right-lsit">
						<?php echo form_input(array('name' => 'advance_of_maney','id'=>'aom', 'value' => '100', 'maxlength' => '3', 'size' => '1', 'style' => 'width:30px')); ?>
					</li>
				</ul>
				<ul class="cart-list">
					<li class="left-lsit">
						<strong><?=lang('total_price')?></strong>
					</li>
					<li class="right-lsit">
						<?php echo  $this->cart->format_number( $total ) . ' ' . $sel_currency;?>
					</li>
				</ul>
				<ul class="cart-list" >
					<li class="left-lsit">
						<strong><?=lang('discount')?></strong>
					</li>
					<li class="right-lsit" >
						<div id="discount_drop_container"><?php echo  $discount_rate ? $discount_rate : 0 ;?>%</div>
					</li>
				</ul>
				<ul class="cart-list">
					<li class="left-lsit">
						<strong><?=lang('tax')?></strong>
					</li>
					<li class="right-lsit">
						<?php echo $this->cart->format_number($exchange->getTax($this->cart->total(),$sel_currency, $discount_rate)) . ' ' . $sel_currency;?>
					</li>
				</ul>
				<ul class="cart-list special-cart-list">
					<li class="left-lsit">
						<?=lang('grant_total')?>
					</li>
					<li class="right-lsit">
						<span id="grant_total_price"><?php echo $this->cart->format_number($total) . '</span> ' . $sel_currency;?>
					</li>
				</ul>
				<a href="JavaScript: goCheckout()" onclick="" class="left" >
					<div class="checkout_btn_left"></div>
					<div class="checkout_btn_midle"><?php echo lang('continue_shop') ?></div>
					<div class="checkout_btn_right"></div>
				</a>
			</div>
			<?php echo form_close();?>
			<div class="clear"></div>
		</div>
	</div>	

	<div class="clear"></div>
</div>
<input type="hidden" id="total_calculator" value="<?=$total?>"/>
<script type="text/javascript">

$(document).ready(function() {
Shadowbox.init();
	real_total= $('#total_calculator').val();
	$('#advance_of_maney').blur(function(){
		total_calculated = Math.ceil(real_total * ($('#advance_of_maney').val()/100)).toFixed(2);
		$('#grant_total_price').html(total_calculated);
	});
	$('.default-value').each(function() {
		var default_value = this.value;
		$(this).focus(function() {
			if(this.value == default_value) {
				this.value = '';
			}
		});
		$(this).blur(function() {
			if(this.value == '') {
				this.value = default_value;
			}
		});
	});	
});
				function goCheckout(){
					if ($("input[name='countItem']").val() == 0){
						var alert_msg = '[no_item_in_cart]';
						if(typeof lang.no_item_in_cart != 'undefined'){
							alert_msg = lang.no_item_in_cart;
						}

						alert(alert_msg);
						return false;
					}
					$('#goCheckout').submit();
				}
				function addDiscount(){
					$.ajax({
						url: settings.base_url + lang.lang_key + '/cart/getDiscountPercent/',
						dataType: 'json',
						data: {'code' : $("#discount_code").val()},
						type: 'POST',
						success: function(data){
							if (data.status) {
								$("#discount_drop_container").html(data.percent + ' %');
								window.location.reload();
							} else {
								$("#question-status-error").html(data.msg).show();
							}
							
						},
						complete: function(data) {

						}
					});	
				}
				
</script>